/*
 * Copyright 2010 Nicolas Lochet Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 *	
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */
package org.nicocube.gwt.parser.stepper.matcher.client;

import java.util.HashSet;
import java.util.Set;

public class ExactTokenMatcher implements TokenMatcher {
	private final String exact;

	public ExactTokenMatcher(String exact) {
		if (exact.length()==0) {
			// TODO, check this exception is semantically the right one
			throw new IndexOutOfBoundsException("This constructor argument cannot be an empty string");
		}
		this.exact = exact;
	}

	@Override
	public Set<Character> firstChars() {
		Set<Character> result = new HashSet<Character>();
		result.add(exact.charAt(0));
		return result ;
	}

	@Override
	public Match match(String s) {
		return new Match(s.startsWith(exact),exact.length());
	}
}
